<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%@ page import =  "com.broadvision.web.util.ViewDynaBean,
		    org.apache.struts.validator.DynaValidatorForm,
                    org.apache.commons.beanutils.PropertyUtils,
                    org.apache.struts.action.DynaActionForm,
                    java.lang.Boolean,
                    java.util.List"
%>

<SCRIPT language="javascript">

function doWebflowAction(theForm,cntOID,version,cntAction){
   var theURL="/cm/launchVSWebflow.do";
   var theParam="?guid="+cntOID+"&version="+version+
             "&launchAction="+cntAction+"&exitURL="+"/cm/closeWindowAlwaysRefresh.do";
   var url = '<html-el:rewrite page="'+theURL+'" />'+theParam;
   var qualifier = window.open(url, "ContentServiceLaunchProcess",
                               "directories=no,height=500,width=650,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");

  if (qualifier != null){
    if (qualifier.opener == null)
        qualifier.opener = self;
    qualifier.focus();
  }

 }
 function doAction(theForm,cntOID,version,cntAction){
   var theURL="/cm/cmProcessMapping.do";
   var theParam="?contentOID="+cntOID+"&version="+version+"&contentAction="+cntAction;
   var url = '<html-el:rewrite page="'+theURL+'" />'+theParam;
   var qualifier = window.open(url, "ContentServiceLaunchProcess",
                              "directories=no,height=500,width=650,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");

   if (qualifier != null){
     if (qualifier.opener == null)
         qualifier.opener = self;
    qualifier.focus();
  }
 }

 function doBVCAction(theForm,cntOID,catOID,cntAction){
   var theURL="/cm/cmBVCProcessMapping.do";
   var theParam="?contentOID="+cntOID+"&categoryOID="+catOID+"&contentTypeId="+theForm.cntTypeId.value+"&contentAction="+cntAction+"&exitURL=/cm/closeWindowAlwaysRefresh.do";
   var url = '<html-el:rewrite page="'+theURL+'" />'+theParam;
   var qualifier = window.open(url, "ContentServiceLaunchProcess",
                              "directories=no,height=500,width=650,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");

   if (qualifier != null){
     if (qualifier.opener == null)
         qualifier.opener = self;
    qualifier.focus();
  }

 }

function onChangeCntType(theForm) {
  theForm.action = '<html-el:rewrite page="/cm/uncatContentBrowse.do"/>';
  theForm.currentPageNumber.value = 0;
  theForm.submit();
}

function toggleContentStatus(formName, contentOid) {
  var theForm = document.forms[formName];
  theForm.action = '<html-el:rewrite page="/cm/toggleContentStatus.do"/>' + '?contentOid=' + contentOid + '&from=uncat';
  theForm.currentPageNumber.value = 0;
  theForm.submit();
}

function checkNumberOnly(e) {
  var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
  if (charCode > 31 && (charCode < 48 || charCode > 57)) {
    return false;
  }
  else {
    return true;
  }
}  

function doGo(formName) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
    if (thisForm.entriesPerPage.value != <c:out value="${cmCntBrowseForm.map.entriesPerPage}"/>) {
      thisForm.currentPageNumber.value = 1;
      thisForm.submit();
      return false;
    }
  }
  return false;
}

function gotoFirstPage(formName) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
    thisForm.currentPageNumber.value = 1;
    thisForm.submit();
    return false;
  }
}

function gotoPreviousPage(formName) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
    var currentPageNumber = thisForm.currentPageNumber.value;
    currentPageNumber--;
    if (thisForm.entriesPerPage.value != <c:out value="${cmCntBrowseForm.map.entriesPerPage}"/>) {
      currentPageNumber = 1;
    }
    if (currentPageNumber > 0) {
      thisForm.currentPageNumber.value = currentPageNumber;
      thisForm.submit();
      return false;
    }
  }
}
  
function gotoNextPage(formName) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
    var currentPageNumber = thisForm.currentPageNumber.value;
    currentPageNumber++;
    if (thisForm.entriesPerPage.value != <c:out value="${cmCntBrowseForm.map.entriesPerPage}"/>) {
      currentPageNumber = 1;
    }
    if (currentPageNumber <= thisForm.totalPageNumber.value) {
      thisForm.currentPageNumber.value = currentPageNumber;
      thisForm.submit();
      return false;
    }
  }
}

function gotoLastPage(formName) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
    if (thisForm.entriesPerPage.value != <c:out value="${cmCntBrowseForm.map.entriesPerPage}"/>) {
      thisForm.currentPageNumber.value = 1;
    }
    else {
      thisForm.currentPageNumber.value = thisForm.totalPageNumber.value;
    }
    thisForm.submit();
    return false;
  }
}

function doCategorySelect(formName, contentOid) {
  var thisForm = document.forms[formName];
  thisForm.contentOid.value = contentOid;      
    
  var cntType = thisForm.cntTypeId.value;
  if (isNaN(cntType)) {
    // 60 is the content type id for BV_CNT_SVCS
    // doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'moveContent', 60, null, null);
    doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'moveContent', 60, null, null, null, null, null, null, null, 'com.broadvision.content.acl.common.CreateContentCategoryPickerFilter', null);

  }
  else {
    // doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'moveContent', thisForm.cntTypeId.value, null, null);
    doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'moveContent', thisForm.cntTypeId.value, null, null, null, null, null, null, null, 'com.broadvision.content.acl.common.CreateContentCategoryPickerFilter', null);
  }
}

function moveContent(ids, names) {
  var thisForm = document.forms['cmCntBrowseForm'];
  
  if (ids[0] == 0) {
    alert('<bean-el:message bundle="cm.messages" key="error.browse.moveContent"/>');
    return false;
  }
  
  thisForm.action = '<html-el:rewrite page="/cm/contentMove.do"/>'+'?action=move'; 
  thisForm.destCategoryOid.value = ids[0];      
  thisForm.catOid.value = 0;   
  thisForm.currentPageNumber.value = 0;
  thisForm.submit();
  return false;
}

function doHistory(formName, contentOid) {
  var theForm = document.forms[formName];
  theForm.action = '<html-el:rewrite page="/cm/viewHistory.do"/>';
  theForm.contentOid.value = contentOid;
  theForm.currentPageNumber.value = 0;
  theForm.submit();
  return false;
}

function doUncheckout(formName, contentOid) {
  var theForm = document.forms[formName];
  theForm.action = '<html-el:rewrite page="/cm/uncheckOut.do"/>';
  theForm.contentOid.value = contentOid;
  theForm.currentPageNumber.value = 0;
  theForm.submit();
  return false;
}  

function doMoveContent(formName, contentOid, catOid) {
  var thisForm = document.forms[formName];
  thisForm.contentOid.value = contentOid;
  thisForm.catOid.value = catOid;

  var cntType = thisForm.cntTypeId.value;
  if (thisForm.formIsCntSvcsContent.value == 'false') {
    doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'moveContent', thisForm.cntTypeId.value, null, null, null, null, null, null, null, 'com.broadvision.content.acl.common.CreateContentCategoryPickerFilter', null);
  } else {
    // 60 is the content type id for BV_CNT_SVCS
    doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'moveContent', 60, null, null, null, null, null, null, null, 'com.broadvision.content.acl.common.CreateContentCategoryPickerFilter', null);
  }
}

function doRefresh() {
  var theForm = document.forms["cmCntBrowseForm"];
  theForm.submit();
}

</SCRIPT>
 
<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<jsp:useBean id="cmCntTypeListView" scope="session" type="com.broadvision.web.util.ViewDynaBean"/>
<jsp:useBean id="cmCntListView" scope="request" type="com.broadvision.web.util.ViewDynaBean"/>
<jsp:useBean id="cmContentAdmin" scope="session" type="java.lang.Boolean"/>

<% String ctxPath = request.getContextPath(); %>

<html-el:form action="/cm/uncatContentBrowse.do">
<input type="hidden" name="catOid"/>
<input type="hidden" name="contentOid"/>
<input type="hidden" name="destCategoryOid"/>
<input type="hidden" name="key"/>
<html-el:hidden property="currentPageNumber"/>
<html-el:hidden property="totalPageNumber"/>
<html-el:hidden property="lastPage"/>
<html-el:hidden property="formIsCntSvcsContent"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
<tr>
  <td valign="top" width="100%">
    <div class="pageTitle"><bean-el:message bundle="cm.messages" key="cm.browse.title"/></div>
    <div class="errorMessage"><html-el:errors bundle="cm.messages"/></div>
    
    <%@include file="/mc/common/pagetab.jsp" %>
  
    <div class="pageSubtitle">
      <span class="left"><bean-el:message bundle="cm.messages" key="cm.browse.type"/>:
      <c:set var="cntList" scope="page" value="${cmCntTypeListView.map.cntTypeList}"/>
      <html-el:select name="cmCntBrowseForm" property="cntTypeId" onchange="onChangeCntType(this.form)"> 
        <html-el:options collection="cntList" property="id" labelProperty="name" />
      </html-el:select>
      </span>
      
    </div>
  
    <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Category" width="100%">
      <tr class="listHeader"> 
        <th id="ContentName" align="left" width="70%">
          <bean-el:message bundle="cm.messages" key="cm.browse.content.name"/>
        </th>
        <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='false'}"> 
        <th id="Status" align="left"  width="10%" nowrap>
          <bean-el:message bundle="cm.messages" key="cm.browse.status"/>
        </th>
        </c:if>
        <th id="Actions" align="left"  width="20%" nowrap>
          <bean-el:message bundle="cm.messages" key="cm.browse.actions"/>
        </th>
      </tr>

      <c:set var="viewImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_view.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.view"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.view"/>'>
      </c:set>   
      <c:set var="editImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>'>
      </c:set>  
      <c:set var="moveImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_move.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.move"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.move"/>'>
      </c:set>

      <c:set var="launchImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_launch.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.launch"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.launch"/>'>
      </c:set>
      
      <c:set var="deleteImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>'>
      </c:set>
      <c:set var="historyImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_history.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.history"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.history"/>'>
      </c:set>
      <c:set var="uncheckoutImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_uncheckout.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.uncheckout"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.uncheckout"/>'>
      </c:set>
      <c:set var="onlineImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.setOnline"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.setOnline"/>'>
      </c:set>
      <c:set var="offlineImg">
      <img src="<%=ctxPath%>/mc/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.setOffline"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.setOffline"/>'>
      </c:set>
      
      <c:choose>
      <c:when test="${not empty cmCntListView.map.contentList}">
      <c:forEach var="content" items="${cmCntListView.map.contentList}" varStatus="status">
        <c:choose>
        <c:when test="${(status.count + 1) % 2 == 0}">
          <tr class="listEven">
        </c:when> 
        <c:otherwise>
	  <tr class="listOdd">
        </c:otherwise>
        </c:choose>

 <td headers="ContentName">
    <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='true'}">  
      <a href="JavaScript:doWebflowAction(document.cmCntBrowseForm,'<c:out value="${content.map.OID}"/>','<c:out value="${content.map.version}"/>','View')" >
    </c:if>
    <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='false'}">  
      <a href="JavaScript:doBVCAction(document.cmCntBrowseForm,'<c:out value="${content.map.OID}"/>','','ViewContent')" >
    </c:if>
    <c:out value="${content.map.key}"/></a>
 </td>
 
         <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='false'}"> 
         <td>
           <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='false'}"> 
           <c:choose>
           <c:when test="${content.map.STATUS == 1}">
             <bean-el:message bundle="cm.messages" key="cm.browse.online"/>
           </c:when>
           <c:otherwise>
             <bean-el:message bundle="cm.messages" key="cm.browse.offline"/>
           </c:otherwise>
           </c:choose>
           </c:if>
         </td>
        </c:if>
        
        <td nowrap align="left" headers="Actions">
    <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='true'}">  
      <a href="JavaScript:doWebflowAction(document.cmCntBrowseForm,'<c:out value="${content.map.OID}"/>','<c:out value="${content.map.version}"/>','Edit')" >
    </c:if>
    <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='false'}">  
      <a href="JavaScript:doBVCAction(document.cmCntBrowseForm,'<c:out value="${content.map.OID}"/>','','EditContent')" >
    </c:if>
    <c:out value='${editImg}' escapeXml="false"/></a>
          <a href='#' onclick="doMoveContent('cmCntBrowseForm', '<c:out value="${content.map.OID}"/>', <c:out value="${cmCntTypeListView.map.currentCatId}"/>)">
            <c:out value='${moveImg}' escapeXml="false"/></a>
    <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='true'}">  
      <a href="JavaScript:doAction(document.cmCntBrowseForm,'<c:out value="${content.map.OID}"/>','<c:out value="${content.map.version}"/>','Review')" >
       <c:out value='${launchImg}' escapeXml="false"/></a>            
    </c:if>
          <c:choose>
          <c:when test="${cmCntTypeListView.map.isTypeVersioned=='true'}">
          <a href='#' onclick="doHistory('cmCntBrowseForm', '<c:out value="${content.map.OID}"/>')">
            <c:out value='${historyImg}' escapeXml="false"/></a>
          </c:when>
	  </c:choose>
          <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='true'}">
          <c:if test="${cmContentAdmin == 'true'}">
          <a href='#' onclick="doUncheckout('cmCntBrowseForm', '<c:out value="${content.map.OID}"/>')">
            <c:out value='${uncheckoutImg}' escapeXml="false"/></a>
          </c:if>
          </c:if>

          <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='false'}"> 
          <c:choose>
          <c:when test="${content.map.STATUS == 0}">
          <a href='#' onclick="toggleContentStatus('cmCntBrowseForm', <c:out value="${content.map.OID}"/>)">
            <c:out value='${onlineImg}' escapeXml="false"/></a>
	  </c:when>
	  <c:otherwise>
	    <a href='#' onclick="toggleContentStatus('cmCntBrowseForm', <c:out value="${content.map.OID}"/>)">
	    <c:out value='${offlineImg}' escapeXml="false"/></a>
	  </c:otherwise>
          </c:choose>
          </c:if>
          
              <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='true'}">  
      <a href="JavaScript:doWebflowAction(document.cmCntBrowseForm,'<c:out value="${content.map.OID}"/>','','Delete')" >
    </c:if>
    <c:if test="${cmCntTypeListView.map.isCntSvcsContent=='false'}">  
      <a href="JavaScript:doBVCAction(document.cmCntBrowseForm,'<c:out value="${content.map.OID}"/>','','DeleteContent')" >
    </c:if>
    <c:out value='${deleteImg}' escapeXml="false"/></a>
        </td>
      
      </tr>
      </c:forEach>
      </c:when>
      <c:otherwise>
        <tr class="listOdd">
          <td colspan=7 align="center"><bean-el:message key="cm.browse.noContent" bundle="cm.messages"/></td>
        </tr>
      </c:otherwise>
      </c:choose>
    </table>

    <c:choose>
    <c:when test="${not empty cmCntListView.map.contentList}">
   
    <div class="pagination">
      
      <bean-el:message key="cm.common.pagination.show" bundle="cm.messages"/>
      <html-el:select property="entriesPerPage" size="1" onchange="doGo('cmCntBrowseForm')">
        <html-el:option value="10">10</html-el:option>
        <html-el:option value="20">20</html-el:option>
        <html-el:option value="30">30</html-el:option>
        <html-el:option value="50">50</html-el:option>
        <html-el:option value="100">100</html-el:option>
      </html-el:select>
      <bean-el:message key="cm.common.pagination.itemsPerPage" bundle="cm.messages"/>          
      &nbsp;&nbsp;
      
      <c:if test="${cmCntBrowseForm.map.totalPageNumber > 1}">

        <c:if test="${cmCntBrowseForm.map.currentPageNumber > 1}">
          <a href="#" class="paginationBtn" onclick="javascript:gotoFirstPage('cmCntBrowseForm')">
            <bean-el:message key="cm.common.pagination.first" bundle="cm.messages"/></a>
          <a href="#" class="paginationBtn" onclick="javascript:gotoPreviousPage('cmCntBrowseForm')">
            <bean-el:message key="cm.common.pagination.previous" bundle="cm.messages"/></a>
        </c:if>
              
        <c:set var="currentPageNumberAttr" scope="page" value="${cmCntBrowseForm.map.currentPageNumber}"/>
        <c:set var="totalPageNumberAttr" scope="page" value="${cmCntBrowseForm.map.totalPageNumber}"/>
        <% Integer currentPageNumberInt = (Integer)pageContext.getAttribute("currentPageNumberAttr"); %>
        <% Integer totalPageNumberInt = (Integer)pageContext.getAttribute("totalPageNumberAttr"); %>
              <bean-el:message key="cm.common.pagination.pageOf" 
                arg0="<%= currentPageNumberInt.toString() %>" 
                arg1="<%= totalPageNumberInt.toString() %>" bundle="cm.messages"/>
              
        <c:if test="${cmCntBrowseForm.map.totalPageNumber > 1}">
          <c:if test="${cmCntBrowseForm.map.currentPageNumber < cmCntBrowseForm.map.totalPageNumber}">
            <a href="#" class="paginationBtn" onclick="javascript:gotoNextPage('cmCntBrowseForm')">
              <bean-el:message key="cm.common.pagination.next" bundle="cm.messages"/></a>
            <a href="#" class="paginationBtn" onclick="javascript:gotoLastPage('cmCntBrowseForm')">
              <bean-el:message key="cm.common.pagination.last" bundle="cm.messages"/></a>
          </c:if>
        </c:if>
              
      </c:if>
    </div>
    
    </c:when>
    <c:otherwise>
      <html-el:hidden property="entriesPerPage"/>
    </c:otherwise>
    </c:choose>
    
  </td>
</tr>
</table>
</html-el:form>
